package com.liliudong.template.generator.entity;

import cn.hutool.core.map.MapUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 表实体
 *
 * @author ldli5
 * @date 2024/7/1-14:22
 */
@Data
@FieldNameConstants
@AllArgsConstructor
@NoArgsConstructor
public class Table {

	/**
	 * 表名称
	 */
	private String tableName;
	/**
	 * 表注释
	 */
	private String tableComment;
	/**
	 * 创建时间
	 */
	private LocalDateTime createTime;

	public static List<Table> fromMaps(List<Map<String, Object>> maps) {
		return maps.stream()
				.map(item -> {
					String tableName = MapUtil.get(item, Fields.tableName, String.class);
					String tableComment = MapUtil.get(item, Fields.tableComment, String.class);
					LocalDateTime createTime = MapUtil.get(item, Fields.createTime, LocalDateTime.class);
					return new Table(tableName, tableComment, createTime);
				})
				.toList();
	}
}
